#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e4 + 5;

int n, m;
struct Node {
  int x, y, z;
} a[N];
int b[N], num;
int f[N], d[N];
void init(int n) { rep(i, 1, n) f[i] = i, d[i] = 0; }
int find(int x) {
  if (f[x] == x) return x;
  int fx = find(f[x]);
  d[x] ^= d[f[x]];
  return f[x] = fx;
}
bool merge(int x, int y, int z) {
  int fx = find(x), fy = find(y);
  if (fx == fy) return (d[x] ^ d[y]) == z;
  f[fy] = fx;
  d[fy] = d[x] ^ d[y] ^ z;
  return true;
}
bool check(int n) {
  init(num);
  rep(i, 1, n) if (!merge(a[i].x, a[i].y, a[i].z)) return false;
  return true;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, m) {
    string r;
    cin >> a[i].x >> a[i].y >> r;
    if (a[i].x > a[i].y) swap(a[i].x, a[i].y);
    if (r == "even")
      a[i].z = 0;
    else
      a[i].z = 1;
  }
  rep(i, 1, m) b[i] = a[i].x - 1, b[i + m] = a[i].y;
  sort(b + 1, b + m * 2 + 1);
  num = unique(b + 1, b + m * 2 + 1) - b - 1;
  rep(i, 1, m) {
    a[i].x = lower_bound(b + 1, b + num + 1, a[i].x - 1) - b;
    a[i].y = lower_bound(b + 1, b + num + 1, a[i].y) - b;
  }
  int l = 1, r = m;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      l = mid + 1;
    else
      r = mid - 1;
  }
  cout << r;
  return 0;
}